<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/5/17
  Time: 22:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>


<title>入库信息 - 入库单</title>

<%--<link rel="stylesheet" href="${contextPath}/static/layer/css/layui.css" media="all">--%>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<%--<link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css">--%>
<link rel="stylesheet"
      href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<%--<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>--%>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/statistics/js/vue.js"></script>

<!-- ztree插件 -->
<link href="${contextPath}/static/ztree/css/zTreeStyle.css" rel="stylesheet" />
<script src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
<script src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>

<%--<jsp:include page="../../../head.jsp"/>--%>
<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }

    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }

    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid-sortable {
        text-align: center;
    }

    .ui-pg-div{
        display: none;
    }
</style>

<div class="row">
    <div class="row btnLine" id="app">
        <div class="button-len col-sm-12">
            <div style="width: 100%; margin-bottom: 2px;">

                <%--<button class="btn btn-white btn-sm btn-purple customBtn" id="addCargo">--%>
                    <%--<i class="ace-icon fa fa-plus-circle purple"></i>--%>
                    <%--<a href="${contextPath}/sys/user/home#page/franchiseePrementDocumentsAdd_order">新增</a>--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="editShop">--%>
                    <%--<i class="ace-icon fa fa-pencil blue"></i> 删单--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 批量打印--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 打印--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 导出--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 设置--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 审核--%>
                <%--</button>--%>
                <%--<div style="width: 100%">--%>
                    <%--<button class="btn btn-white btn-info btn-sm customBtn" id="fqchuk">--%>
                        <%--<i class="ace-icon fa fa-bicycle red"></i> 发起出库--%>
                    <%--</button>--%>
                    <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                        <%--<i class="ace-icon fa fa-bicycle red"></i> 出库分捡--%>
                    <%--</button>--%>
                <%--</div>--%>

                    <label style="margin-left: 10px;">选择区域：</label>
                    <input id="zoneCode" class="form-control input-sm" type="text" placeholder="区域id" style="display: none">
                    <input id="zoneName" onfocus="this.value=''" class="input-sm" type="text" placeholder="区域名称" style="width: 100px;" onclick="zoneHs()" readonly>


                    <label style="margin-left: 10px;">选择店铺：</label>
                    <input id="shopId" class="form-control input-sm" type="text" placeholder="店铺id" style="display: none">
                    <input id="shopName" onfocus="this.value=''" class="input-sm" type="text" placeholder="店铺名称" style="margin-top: -5px; width: 300px;">

                    <label style="">入库类型：</label>
                    <select class="input-sm" id="exType">
                        <option value="">==请选择==</option>
                        <%--<option value="3">直采入库单</option>--%>
                        <%--<option value="4">统采入库单</option>--%>
                        <%--<option value="6">调拨入库单</option>--%>
                        <%--<option value="2">直配入库单</option>--%>
                        <%--<option value="1">直配返仓单</option>--%>
                        <%--<option value="5">调拨返仓单</option>--%>
                        <%--<option value="20">调拨返仓单</option>--%>
                        <option value="1">仓配返仓单</option>
                        <option value="2">仓配入库单</option>
                        <option value="3">直配入库单</option>
                        <option value="4">统采入库单</option>
                        <option value="5">调拨返仓单</option>
                        <option value="6">调拨入库单</option>
                        <option value="7">损益入库单</option>
                        <option value="8">仓配退货入库单</option>
                        <option value="9">直配退货入库单</option>
                        <option value="10">统采退货入库单</option>
                        <option value="20">移动调库单</option>
                    </select>

                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                    <%--<i class="ace-icon fa fa-key red"></i>--%>
                <%--</button>--%>
                    <label>单据状态: </label>
                    <select id="approveFlag">
                        <option value="-1">==>请选择<==</option>
                        <option value="2">==>待处理<==</option>
                        <option value="3">==>处理中<==</option>
                        <option value="1">==>完成<==</option>
                    </select>
                <input type="text" class="input-sm" id="beginTime" placeholder="开始时间" style="width: 120px;"/>
                -
                <input type="text" class="input-sm" id="endTime" placeholder="结束时间" style="width: 120px;"/>
                    <button class="btn btn-sm btn-white btn-info search-len customBtn"
                            onclick="searchEnter()">
                        <i class="ace-icon fa fa-search orange"></i>查询
                    </button>
                <%----%>
                <%--<select id="stateInput">--%>
                    <%--<option value="-1">==审核状态==</option>--%>
                    <%--<option value="3">待审核</option>--%>
                    <%--<option value="1">通过</option>--%>
                    <%--<option value="4">拒绝</option>--%>
                    <%--<option value="0">无效</option>--%>
                <%--</select>--%>
            </div>
        </div>
    </div>

    <div class="col-xs-12">

        <table id="grid-table"></table>

        <div id="grid-pager"></div>

    </div>

    <!-- 新增修改数型内容 -->
    <div id="authorizationInfoContentEnter" class="hide">
        <div class="content_wrap" id="treeDemoProd">
            <div class="zTreeDemoBackgroundProd left" style="width: 440px; margin-left: 5px;">
                <form id="enterForm">
                    <div class="form-group">
                        <input class="hide" id="orderId" value="">
                        <input class="hide" id="type" value="">
                        <textarea class="form-control" id="remark" rows="8"></textarea>
                    </div>
                </form>
            </div>
        </div>
        <div>
            <button id="enterBtn" class="btn btn-success btn-sm" style="left: 393px;top: 218px;position: fixed;">确认</button>
        </div>
    </div>

    <!-- 区域数型内容 -->
    <div id="authorizationInfoContentZone" class="hide">
        <div class="content_wrap">
            <div class="zTreeDemoBackground left">
                <ul id="zoneDemo" class="ztree"></ul>
            </div>
        </div>

        <div>
            <%--<button id="getShopIdBtn" class="btn btn-success btn-sm" style="left: 250px;top: 450px;position: fixed;">确认</button>--%>
        </div>
    </div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<!-- 公用属性 -->
<script type="text/javascript">
    var shopIds = '';

    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";


    //获取选择数据的Id，（获取单条数据id 使用selrow，获取多条数据Id 使用selarrrow）
    //    var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
    //获取选择数据的的整条数据（数据类型 集合）
    //    var rowData = $(grid_selector).jqGrid('getRowData', id);
    //获取选择数据的Id，（数组类型）
    //    var ids = $(grid_shop_selector).jqGrid('getGridParam', 'selarrrow');


    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var queryModel = {
        //分页参数
        page: '1',
        rows: '10',
    }

    var app = new Vue({
        el: '#app',
        data: {
            objcte: [],
            yanType1: [],
            yanType2: [],
            yanType3: [],
            yanType4: [],
            yanType5: []
        },
        methods: {
//            addProduct: function () {
//                shopInfo();
//                $('#myModal').modal('show');
//            }
        }
    })
</script>

<%--<script type="text/javascript" src="${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js"></script>--%>
<%--<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js"></script>--%>
<%--<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js"></script>--%>
<%--<script type="text/javascript" src="${contextPath}/static/layer/layer.js"></script>--%>
<script type="text/javascript">
    var getShopInstockOrderListByPage = function (shopId) {
        var filters = {
            "rules": [
                {"field": "state", "data": '1'},
                {"field": "shopId", "data": shopId}
            ]
        };
        var grid_data = {'filters': JSON.stringify(filters)};

        var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js", null]
        $('.page-content-area').ace_ajax('loadScripts', scripts, function () {

            jQuery(function ($) {

                var parent_column = $(grid_selector).closest('[class*="col-"]');
                //resize to fit page size
                $(window).on('resize.jqGrid', function () {
                    $(grid_selector).jqGrid('setGridWidth', parent_column.width());
                })

                //resize on sidebar collapse/expand
                $(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
                    if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
                        //setTimeout is for webkit only to give time for DOM changes and then redraw!!!
                        setTimeout(function () {
                            $(grid_selector).jqGrid('setGridWidth', parent_column.width());
                        }, 20);
                    }
                })

                console.log(grid_data);

                jQuery(grid_selector).jqGrid({
                    //direction: "rtl",

                    //subgrid options
                    subGrid: false,
                    url: "${contextPath}/ktPurchase/getShopInstockOrderListByPage",
                    postData: grid_data,
                    datatype: "json",
                    mtype: 'POST',
                    height: 300,
                    colNames: ['单号','审核状态','出库方','出库方Id','接收方','接收方ID','单据金额','操作员Id','操作员','操作日期','单据状态','订单类型', '备注'],
                    colModel: [
                        {name:'id',index:'id',formatter: cLink, width:110,editable:true},
                        {
                            name: 'repertoryId',
                            index: 'repertoryId',
                            editable: true,
                            hidden: true,
                            sortable: false,
                            editrules: {required: true,
    //                            custom: true   //
                            }
                        },
                        {
                            name: 'requireShopName',
                            index: 'requireShopName',
                            editable: true,
                            sortable: false,
    //                    edittype: 'select',
                            <%--editoptions: {dataUrl: '${contextPath}/sys/role/getRoleInfoToSelect'},--%>
                            editrules: {required: true}
                        },
                        {name: 'shopId', index: 'shopId', editable: false, hidden: true,sortable: false},
                        {name: 'shopName', index: 'shopName', editable: false, sortable: false},
                        {
                            name: 'requireShopId',
                            index: 'requireShopId',
                            editable: true,
                            sortable: false,
                            hidden: true,
    //                    edittype: 'select',
                            <%--editoptions: {dataUrl: '${contextPath}/sys/role/getRoleInfoToSelect'},--%>
                            editrules: {required: true}
                        },
                        {
                            name: 'amt',
                            index: 'amt',
                            editable: true,
                            sortable: false,
                        },
                        {name: 'createUser', index: 'createUser', editable: true, sortable: false, hidden: true},
                        {name: 'createUserName', index: 'createUserName', editable: true, sortable: false},
                        {name: 'createTime', index: 'createTime', editable: true, sortable: false},
                        {
                            name: 'approveFlag',
                            index: 'approveFlag',
                            width: 100,
                            editable: true,
                            sortable: false,
                            formatter:function(cellvalue, options, rowObject) {
                                var status = rowObject.approveFlag;
                                if (status == "1"){
                                    return "完成";
                                }else if (status == "3"){
                                    return "处理中";
                                }else 
                                	return '待处理'
                            }

                        },
                        {name: 'type', index: 'type', editable: true, sortable: false,
                            formatter:function(cellvalue, options, rowObject) {
                                var type = rowObject.type;
                                if (type == "1"){
                                    return "仓配返仓单";
                                }
                                if (type == "2"){
                                    return "仓配入库单";
                                }
                                if (type == "3"){
                                    return "直配入库单";
                                }
                                if (type == "4"){
                                    return "统采入库单";
                                }
                                if (type == "5"){
                                    return "调拨返仓单";
                                }
                                if (type == "6"){
                                    return "调拨入库单";
                                }
                                if (type == "7"){
                                    return "损益入库单";
                                }
                                if (type == '8'){
                                    return "仓配退货入库单";
                                }
                                if (type == "9"){
                                    return "直配退货入库单";
                                }
                                if (type == "10"){
                                    return "统采退货入库单";
                                }
                                if (type == '20'){
                                    return "移动调整";
                                }
                                return "移动调整";
                            }},
                        {name: 'remark', index: 'remark', editable: true, sortable: false, formatter: remarkCk},
                    ],
                    rownumbers: true,
                    sortname: "gmtModifiedStr",
                    sortorder: "desc",
                    viewrecords: true,
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    pager: pager_selector,
                    altRows: true,
    //                toppager: true,

                    multiselect: false,
                    //multikey: "ctrlKey",
                    multiboxonly: false,

                    loadComplete: function () {
                        var table = this;
                        setTimeout(function () {
                            styleCheckbox(table);

                            updateActionIcons(table);
                            updatePagerIcons(table);
                            enableTooltips(table);
                        }, 0);
                    },

                    editurl: "${contextPath}/ktPurchase/saveSupplier",//nothing is saved
                    caption: "入库信息",
                    jsonReader: {
                        root: "recordList",
                        page: "currentPage",
                        total: "pageCount",
                        records: "recordCount"
                    }

                    //,autowidth: true,


                    /**
                     ,
                     grouping:true,
                     groupingView : {
                     groupField : ['name'],
                     groupDataSorted : true,
                     plusicon : 'fa fa-chevron-down bigger-110',
                     minusicon : 'fa fa-chevron-up bigger-110'
                },
                     caption: "Grouping"
                     */

                });

                function cLink(cellvalue, options, rowObject){
                    //console.log(rowObject)
                    var id = rowObject.id;
                    var type = rowObject.type;
                    var approveFlag = rowObject.approveFlag;
                    return '<a href="${contextPath}/sys/user/home#page/franchiseePrementDocumentsEnter_warehouse_info&id='+id+'&type='+type+'&approveFlag='+approveFlag+'" onclick="">'+id+'</a>';
                }

                function   remarkCk(cellvalue, options, rowObject){
                    var id = rowObject.id;
                    var type = rowObject.type;
                    var remark = rowObject.remark;
                    if (!remark){
                        remark = "-";
                    }
                    return '<div id="'+id+'_'+type+'" name="'+type+'" onclick="remarkAt(this.id)">'+remark+'</a>';
                }

                $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

                $("#editShop").click(function () {
                    var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
                    if (!id) {
                        $.jgrid.info_dialog("提示：", "请选择一条信息");
                        return;
                    }
                    $(grid_selector).jqGrid("editGridRow", id, {
                        // edit record form
                        width: 500,
                        closeAfterEdit: true,
                        //editData :
                        recreateForm: true,
                        viewPagerButtons: false,
                        beforeShowForm: function (e) {
                            var form = $(e[0]);
                            form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
                                .wrapInner('<div class="widget-header" />');
                            style_edit_form(form);
                        },
                        afterShowForm: function (e) {
                            var form = $(e[0]);
                            ////console.log(form)

                            $.ajax({
                                url: '${contextPath}/ktPurchase/saveSupplier',
                                success: function (data) {
                                    if (data.success) {
                                        var countries = data.data
                                        $('#quXianName').autocomplete({
                                            lookup: countries,
                                            onSelect: function (suggestion) {
                                                //alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                                                //selectChannelNameToSelected(suggestion.value)
                                            },
                                            width: 200,
                                            minChars: 0,
                                        });
                                    }
                                }
                            });

                            $.ajax({
                                url: '${contextPath}/checking/selectEmpNameToSelected?channelName=',
                                success: function (data) {
                                    if (data.success) {
                                        var countries = data.data
                                        $('#empName').autocomplete({
                                            lookup: countries,
                                            onSelect: function (suggestion) {
                                                //////console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);
                                            },
                                            width: 200,
                                            minChars: 0,
                                        });
                                    }
                                }
                            });

                            $.ajax({
                                url: '${contextPath}/checking/selectChannelNameToSelected?quXianName=',
                                success: function (data) {
                                    if (data.success) {
                                        var countries = data.data
                                        $('#realChannelName').autocomplete({
                                            lookup: countries,
                                            onSelect: function (suggestion) {
                                                //alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                                            },
                                            width: 200,
                                            minChars: 0,
                                        });
                                    }
                                }
                            });

                            $.ajax({
                                url: '${contextPath}/checking/selectMaterialCompanyToSelected',
                                success: function (data) {
                                    if (data.success) {
                                        var countries = data.data
                                        $('#materialCompany').autocomplete({
                                            lookup: countries,
                                            onSelect: function (suggestion) {
                                                //alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                                            },
                                            width: 200,
                                            minChars: 0,
                                        });
                                    }
                                }
                            })

                        },
                        afterSubmit: function (response, postdata) {
                            var result = eval('(' + response.responseText + ')');
                            //////console.log(result);
                            return [result.success, result.message, 0];
                        },
                        errorTextFormat: function (response) {
                            //////console.log("错误"+response.responseText);
                            //var result = response.responseText;
                            return "服务器异常，稍后再试";
                        }
                    });
                });


                //新增事件
                $("#addCargo").click(function () {

                    <%--$(grid_selector).jqGrid("editGridRow", 'new', {--%>
                        <%--//new record form--%>
                        <%--//width: 700,--%>
                        <%--closeAfterAdd: true,--%>
                        <%--recreateForm: true,--%>
                        <%--viewPagerButtons: false,--%>
                        <%--beforeShowForm: function (e) {--%>
                            <%--var form = $(e[0]);--%>
                            <%--form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')--%>
                                <%--.wrapInner('<div class="widget-header" />')--%>
                            <%--style_edit_form(form);--%>
                        <%--},--%>
                        <%--afterShowForm: function (e) {--%>
                            <%--var form = $(e[0]);--%>
                            <%--////console.log(form)--%>

                            <%--$.ajax({--%>
                                <%--url: '${contextPath}/checking/selectQuXianNameToSelected',--%>
                                <%--success: function (data) {--%>
                                    <%--if (data.success) {--%>
                                        <%--var countries = data.data--%>
                                        <%--$('#quXianName').autocomplete({--%>
                                            <%--lookup: countries,--%>
                                            <%--onSelect: function (suggestion) {--%>
                                                <%--//alert('You selected: ' + suggestion.value + ', ' + suggestion.data);--%>
                                                <%--//selectChannelNameToSelected(suggestion.value)--%>
                                            <%--},--%>
                                            <%--width: 200,--%>
                                            <%--minChars: 0,--%>
                                        <%--});--%>
                                    <%--}--%>
                                <%--}--%>
                            <%--});--%>

                            <%--$.ajax({--%>
                                <%--url: '${contextPath}/checking/selectEmpNameToSelected?channelName=',--%>
                                <%--success: function (data) {--%>
                                    <%--if (data.success) {--%>
                                        <%--var countries = data.data--%>
                                        <%--$('#empName').autocomplete({--%>
                                            <%--lookup: countries,--%>
                                            <%--onSelect: function (suggestion) {--%>
                                                <%--//////console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);--%>
                                            <%--},--%>
                                            <%--width: 200,--%>
                                            <%--minChars: 0,--%>
                                        <%--});--%>
                                    <%--}--%>
                                <%--}--%>
                            <%--});--%>

                            <%--$.ajax({--%>
                                <%--url: '${contextPath}/checking/selectChannelNameToSelected?quXianName=',--%>
                                <%--success: function (data) {--%>
                                    <%--if (data.success) {--%>
                                        <%--var countries = data.data--%>
                                        <%--$('#realChannelName').autocomplete({--%>
                                            <%--lookup: countries,--%>
                                            <%--onSelect: function (suggestion) {--%>
                                                <%--//alert('You selected: ' + suggestion.value + ', ' + suggestion.data);--%>
                                            <%--},--%>
                                            <%--width: 200,--%>
                                            <%--minChars: 0,--%>
                                        <%--});--%>
                                    <%--}--%>
                                <%--}--%>
                            <%--});--%>

                            <%--$.ajax({--%>
                                <%--url: '${contextPath}/checking/selectMaterialCompanyToSelected',--%>
                                <%--success: function (data) {--%>
                                    <%--if (data.success) {--%>
                                        <%--var countries = data.data--%>
                                        <%--$('#materialCompany').autocomplete({--%>
                                            <%--lookup: countries,--%>
                                            <%--onSelect: function (suggestion) {--%>
                                                <%--//alert('You selected: ' + suggestion.value + ', ' + suggestion.data);--%>
                                            <%--},--%>
                                            <%--width: 200,--%>
                                            <%--minChars: 0,--%>
                                        <%--});--%>
                                    <%--}--%>
                                <%--}--%>
                            <%--})--%>

                        <%--},--%>
                        <%--afterSubmit: function (response, postdata) {--%>
                            <%--var result = eval('(' + response.responseText + ')');--%>
                            <%--//////console.log(result);--%>
                            <%--return [result.success, result.message, 0];--%>
                        <%--},--%>
                        <%--errorTextFormat: function (response) {--%>
                            <%--//////console.log("错误"+response.responseText);--%>
                            <%--//var result = response.responseText;--%>
                            <%--return "服务器异常，稍后再试";--%>
                        <%--}--%>
                    <%--});--%>

                })

                $("#initializeUserPassword").click(function () {
                    var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
                    if (!id) {
                        $.jgrid.info_dialog("提示：", "请选择一条用户信息");
                        return;
                    }
                    //询问框
                    layer.confirm('将会把用户密码初始化为用户的手机号码', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        var rowData = $(grid_selector).jqGrid('getRowData', id);
                        layer.load(1);
                        $.ajax({
                            url: '${contextPath}/sys/user/initializeUserPassword?phone=' + rowData.phone,
                            // async : false,
                            success: function (data) {
                                layer.closeAll('loading');
                                if (data.success) {
                                    layer.msg('初始化成功', {icon: 1});

                                } else {
                                    layer.msg(data.message);
                                }

                            },
                            error: function (error) {
                                layer.closeAll('loading');
                                $.jgrid.info_dialog("提示：", "服务器异常，稍后再试");
                            }

                        })

                    }, function () {

                    });
                })
                //enable search/filter toolbar
                //jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
                //jQuery(grid_selector).filterToolbar({});


                //switch element when editing inline
                function aceSwitch(cellvalue, options, cell) {
                    setTimeout(function () {
                        $(cell).find('input[type=checkbox]')
                            .addClass('ace ace-switch ace-switch-5')
                            .after('<span class="lbl"></span>');
                    }, 0);
                }

                //enable datepicker
                function pickDate(cellvalue, options, cell) {
                    setTimeout(function () {
                        $(cell).find('input[type=text]')
                            .datepicker({format: 'yyyy-mm-dd', autoclose: true});
                    }, 0);
                }


                //navButtons
                jQuery(grid_selector).jqGrid('navGrid', pager_selector,
                    { 	//navbar options
                        edit: false,
                        editicon: 'ace-icon fa fa-pencil blue',
                        add: false,
                        addicon: 'ace-icon fa fa-plus-circle purple',
                        del: false,
                        delicon: 'ace-icon fa fa-trash-o red',
                        search: false,
                        searchicon: 'ace-icon fa fa-search orange',
                        refresh: true,
                        refreshicon: 'ace-icon fa fa-refresh green',
                        view: false,
                        viewicon: 'ace-icon fa fa-search-plus grey',
                    },
                    {
                        //edit record form
                        //closeAfterEdit: true,
                        //width: 700,
                        recreateForm: true,
                        beforeShowForm: function (e) {
                            var form = $(e[0]);
                            form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
                            style_edit_form(form);
                        }
                    },
                    {
                        //new record form
                        //width: 700,
                        closeAfterAdd: true,
                        recreateForm: true,
                        viewPagerButtons: false,
                        beforeShowForm: function (e) {
                            var form = $(e[0]);
                            form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
                                .wrapInner('<div class="widget-header" />')
                            style_edit_form(form);
                        }
                    },
                    {
                        //delete record form
                        recreateForm: true,
                        beforeShowForm: function (e) {
                            var form = $(e[0]);
                            if (form.data('styled')) return false;

                            form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
                            style_delete_form(form);

                            form.data('styled', true);
                        },
                        onClick: function (e) {
                            //alert(1);
                        }
                    },
                    {
                        //search form
                        recreateForm: true,
                        afterShowSearch: function (e) {
                            var form = $(e[0]);
                            form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
                            style_search_form(form);
                        },
                        afterRedraw: function () {
                            style_search_filters($(this));
                        }
                        ,
                        multipleSearch: true,
                        /**
                         multipleGroup:true,
                         showQuery: true
                         */
                    },
                    {
                        //view record form
                        recreateForm: true,
                        beforeShowForm: function (e) {
                            var form = $(e[0]);
                            form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
                        }
                    }
                )


                function style_edit_form(form) {
                    //enable datepicker on "sdate" field and switches for "stock" field
                    //form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})

                    //form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
                    //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
                    //.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');


                    //update buttons classes
                    var buttons = form.next().find('.EditButton .fm-button');
                    buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
                    buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
                    buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

                    buttons = form.next().find('.navButton a');
                    buttons.find('.ui-icon').hide();
                    buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
                    buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
                }

                function style_delete_form(form) {
                    var buttons = form.next().find('.EditButton .fm-button');
                    buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
                    buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
                    buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
                }

                function style_search_filters(form) {
                    form.find('.delete-rule').val('X');
                    form.find('.add-rule').addClass('btn btn-xs btn-primary');
                    form.find('.add-group').addClass('btn btn-xs btn-success');
                    form.find('.delete-group').addClass('btn btn-xs btn-danger');
                }

                function style_search_form(form) {
                    var dialog = form.closest('.ui-jqdialog');
                    var buttons = dialog.find('.EditTable')
                    buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
                    buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
                    buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
                }

                function beforeDeleteCallback(e) {
                    var form = $(e[0]);
                    if (form.data('styled')) return false;

                    form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
                    style_delete_form(form);
                    form.data('styled', true);
                }

                function beforeEditCallback(e) {
                    var form = $(e[0]);
                    form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
                    style_edit_form(form);
                }


                //it causes some flicker when reloading or navigating grid
                //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
                //or go back to default browser checkbox styles for the grid
                function styleCheckbox(table) {
                    /**
                     $(table).find('input:checkbox').addClass('ace')
                     .wrap('<label />')
                     .after('<span class="lbl align-top" />')


                     $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
                     .find('input.cbox[type=checkbox]').addClass('ace')
                     .wrap('<label />').after('<span class="lbl align-top" />');
                     */
                }


                //unlike navButtons icons, action icons in rows seem to be hard-coded
                //you can change them like this in here if you want
                function updateActionIcons(table) {
                    /**
                     var replacement =
                     {
                         'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
                         'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
                         'ui-icon-disk' : 'ace-icon fa fa-check green',
                         'ui-icon-cancel' : 'ace-icon fa fa-times red'
                     };
                     $(table).find('.ui-pg-div span.ui-icon').each(function(){
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
                    if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
                })
                     */
                }

                //replace icons with FontAwesome icons like above
                function updatePagerIcons(table) {
                    var replacement =
                        {
                            'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                            'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                            'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                            'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
                        };
                    $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
                        var icon = $(this);
                        var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                        if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
                    })
                }

                function enableTooltips(table) {
                    $('.navtable .ui-pg-button').tooltip({container: 'body'});
                    $(table).find('.ui-pg-div').tooltip({container: 'body'});
                }

                //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

                $(document).one('ajaxloadstart.page', function (e) {
                    $.jgrid.gridDestroy(grid_selector);
                    $('.ui-jqdialog').remove();
                });
            });
        });
    }
</script>
<%--<script src=${contextPath}/static/layer/layui.all.js></script>--%>
<script type="text/javascript">
    /**
     * 搜索
     */
    function searchEnter() {
        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();
        var type = $("#exType").val();
        var approveFlag = $("#approveFlag").val();
        var shopId = $("#shopId").val();

        if(shopId == ""){
            shopId = shopIds
        }

        var filters = {
            "rules": [
                {
                "field": "beginDate",
                "data": beginTime
                }, {
                    "field": "endDate",
                    "data": endTime
                }, {
                    "field": "type",
                    "data": type
                }, {
                    "field": "approveFlag",
                    "data": approveFlag
                },
                {"field": "state", "data": '1'},
                {"field": "shopId", "data": shopId}
            ]
        };
        console.log(filters)
        jQuery("#grid-table").jqGrid('setGridParam', {
            postData: {
                "filters": JSON.stringify(filters) //"{'rules' : [{'field' : 'shopName','data' : "+shopName+"},{'field' : 'state','data' : "+state+"}]}"
            }
        }).trigger("reloadGrid");
    }

    function isPhone(phone) {
        var tel = /^1[34578]\d{9}$/;
        return [tel.test(phone), '电话：格式不对']
    }




    $('#beginTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });


    $('#endTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });
</script>
<!-- 业务 -->
<script type="text/javascript">

    //发起入库
    $("#fqchuk").click(function () {
        var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
        if(!id){
            layer.msg("提示：请选择一条订单")
            return
        }
        var rowData = $(grid_selector).jqGrid('getRowData', id);
        //订单Id
        var orderId = rowData.id.split(">")[1].split("<")[0];
        queryModel.id = orderId;
        queryModel.approveFlag = '3';
        //console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktPurchase/shopOutstockOrderCheck',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    });

    //入库完成
    $("#ckwanc").click(function () {
        var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
        if(!id){
            layer.msg("提示：请选择一条订单")
            return
        }
        var rowData = $(grid_selector).jqGrid('getRowData', id);
        //订单Id
        var orderId = rowData.id.split(">")[1].split("<")[0];
        queryModel.id = orderId;
        //console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktPurchase/shopConfirmOutstockOrder',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    });

    //保存备注
    $("#enterBtn").click(function () {
        var remark = $("#remark").val();
        if(remark == "" || remark == null){
            layer.msg("提示：备注内容不能为空");
            return
        }
        var id = $("#orderId").val();
        var type = $("#type").val();

        var model = {id: id, remark: remark, type: type}
        console.log(model)
        layer.load(1);
        $.ajax({
            url: '${contextPath}/ktPurchase/shopInstockOrderCheck',
            type: 'post',
            data: model,
            success: function (data) {

                layer.close(modalIndex);
                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
                layer.closeAll('loading')
            }
        })

    })

    var reload = function () {
//        $(grid_selector).jqGrid('clearGridData');  //清空表格
        $(grid_selector).jqGrid('setGridParam',{
            url:"${contextPath}/ktPurchase/getShopInstockOrderListByPage",
            datatype:'json',
//                    postData:param,
            page:1
        }).trigger("reloadGrid"); //重新载入
    }


    //-- 弹出品牌 --
    var remarkAt = function (id){
        var idz = id.split("_")[0];
        var type = id.split("_")[1];
        layer.load(1);
        $("#orderId").val(idz);
        $("#type").val(type);
        $("#remark").val("");
        $("#authorizationInfoContentEnter").removeClass("hide")
        modalIndex = layer.open({
            type: 1,
            title: '订单备注',
            closeBtn: 1,
            shadeClose: true,
            maxmin: true,
            area: ['450px', '255px'],
            skin: 'yourclass',
            content: $("#authorizationInfoContentEnter"),
            end: function () {
                $("#authorizationInfoContentEnter").addClass("hide")
            }
        });
        layer.closeAll('loading')
    }

</script>

<!-- 店铺加载 -->
<script type="text/javascript">

    var getShop = function () {
        var queryModel = {}
        var zoneCode = $("#zoneCode").val();
        var filters = {
            "rules": [
                {
                    "field": "type",
                    "data": 'kt'
                },
                {
                    "field" : "state",
                    "data": '1'
                },
                {"field" : "zoneCode", "data": zoneCode}
            ]
        };
        queryModel.state = '5';
        queryModel.shopType = "'中深'";
        queryModel.zoneCode = zoneCode;
        queryModel.filters = JSON.stringify(filters);


        console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktCommon/getShopList2User',
            type: 'post',
            data: queryModel,
            success: function (data) {
                var dataArray = data;

                var shopArray = []
                for(var i = 0; i < dataArray.length; i++){
                    if(shopIds == ''){
                        shopIds = dataArray[i].shopId;
                    }else {
                        shopIds = shopIds + ',' + dataArray[i].shopId;
                    }


                    var shop = {}
                    shop.value = data[i].shopName;
                    shop.data = data[i].shopId;
                    shopArray.push(shop);
                    shopId = data[i].shopId;
                    shopName = data[i].shopName;
                }
                var countries = shopArray
                $('#shopName').autocomplete({
                    lookup: countries,
                    onSelect: function (suggestion) {
//                         alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        $('#shopId').val(suggestion.data);
                    },
                    minChars: 0,
                });
                console.log(shopIds)

                getShopInstockOrderListByPage(shopIds);

            },
            error: function (error){
                layer.msg("获取出错："+data.message)
            }
        })
    }

    $('#shopId').change(function () {
        var shopId = $("#shopId").val();
//        var phone = $("#phone").val();
        //var parentDepartmentkey = $("#id_parentDepartmentkey_name").val();

        var filters = {
            "rules": [
                {
                    "field": "shopId",
                    "data": shopId
                }
            ]
        };
        //console.log(filters)
        $(grid_selector).jqGrid('clearGridData');  //清空表格
//        jQuery("#grid-table").jqGrid('setGridParam', {
//            postData: {
//                "filters": JSON.stringify(filters) //"{'rules' : [{'field' : 'shopName','data' : "+shopName+"},{'field' : 'state','data' : "+state+"}]}"
//            }
//        }).trigger("reloadGrid");
    })

    //获取区域
    var getZone = function(){
        layer.load(1);
        var filters = {
            "rules": [
                {"field": "parentId", "data": '0'},
                {"field": "state", "data": '1'},
            ]
        };
        var queryModels = {
            page: '1',
            rows: '10000',
            filters: JSON.stringify(filters),
        };

        $.ajax({
            url : "${contextPath}/ktCommon/getZoneListByPage",
            type : "get",
            data : queryModels,
            dataType : "json",
            async : false,
            success : function(data) {
                layer.closeAll('loading');
                var dataArray = data.recordList;
                zoneArray = dataArray;
            },
            error : function () {
                layer.closeAll('loading');
                layer.msg("网络异常")
            }
        });
    }

    var zoneHs = function () {
        $("#zoneName").val('');
        $("#zoneCode").val('');
        getShop();

        var setting = {
            view: {
                dblClickExpand: false,
                showLine: true,
                selectedMulti: false
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "parentId",
                    rootPId: '0',
                },
                key: {
                    name: 'zoneName'
                }
            },
            <%--async: {--%>
            <%--enable: false, // 设置 zTree是否开启异步加载模式  加载全部信息--%>
            <%--url: "${contextPath}/ktProd/getProdType", // Ajax 获取数据的 URL 地址--%>
            <%--autoParam: ["0"],    // 异步加载时自动提交父节点属性的参数,假设父节点 node = {id:1, name:"test"}，异步加载时，提交参数 zId=1--%>
            <%--//                dataFilter: queryModels,--%>
            <%--},--%>
            callback: { //回调函数
                /**
                 * event:鼠标事件
                 * treeId：树的容器id
                 * treeNode：当前点击的节点
                 */
                //双击
                onDblClick: function (treeId, treeNode) {
                    var treeObj = $.fn.zTree.getZTreeObj("zoneDemo");
                    var node = treeObj.getSelectedNodes();//点击节点后 获取节点数据
                    console.log(node[0].zoneName)
                    $("#zoneName").val(node[0].zoneName);
                    $("#zoneCode").val(node[0].zoneCode);
                    getShop();
                    layer.close(modalIndexZone)
                }
            }
        }
        console.log(zoneArray)

        var zNodes =[];
        $.fn.zTree.init($("#zoneDemo"), setting, zoneArray);
        $("#authorizationInfoContentZone").removeClass("hide")
        modalIndexZone = layer.open({
            type: 1,
            title: '区域',
            closeBtn: 1,
            shadeClose: true,
            maxmin: true,
            area: ['300px','500px'],
            skin: 'yourclass',
            content: $("#authorizationInfoContentZone"),
            end: function () {
                $("#authorizationInfoContentZone").addClass("hide")
            }
        });
    }

    $(function () {
        getZone();
        getShop();
    })

</script>
